<template>
<div>
  <h1>Log</h1>
  <!--搜索框-->
  <el-form :inline="true" ref="form" :model="queryLike" label-width="80px">
    <el-form-item label="操作权限">
      <el-input v-model="queryLike.userCode" placeholder="输入要查找的权限"></el-input>
    </el-form-item>
    <el-form-item label="IP地址">
      <el-input v-model="queryLike.ip" placeholder="输入要查找的ip地址"></el-input>
    </el-form-item>
    <br>
    <el-form-item label="操作类型">
      <el-input v-model="queryLike.type" placeholder="输入要查找的操作类型"></el-input>
    </el-form-item>
    <el-form-item label="介绍">
      <el-input v-model="queryLike.describe" placeholder="输入要查找的内容"></el-input>
    </el-form-item>
    <br>
    <el-form-item label="创建时间">
      <el-col :span="11">
        <el-date-picker type="date" placeholder="选择开始日期" v-model="queryLike.startTime1"
                        style="width: 100%;"></el-date-picker>
      </el-col>
      <el-col class="line" :span="2" style="text-align:center">-</el-col>
      <el-col :span="11">
        <el-time-picker placeholder="选择开始时间" v-model="queryLike.startTime2" style="width: 100%;"></el-time-picker>
      </el-col>
    </el-form-item>
    <el-form-item>
      <el-col :span="11">
        <el-date-picker type="date" placeholder="选择结束日期" v-model="queryLike.endTime1"
                        style="width: 100%;"></el-date-picker>
      </el-col>
      <el-col class="line" :span="2" style="text-align:center">-</el-col>
      <el-col :span="11">
        <el-time-picker placeholder="选择结束时间" v-model="queryLike.endTime2" style="width: 100%;"></el-time-picker>
      </el-col>
    </el-form-item>
    <br>
    <el-form-item label="模块名称">
      <el-input v-model="queryLike.model" placeholder="输入模块名称"></el-input>
    </el-form-item>
    <el-form-item label="运行时间">
      <el-input v-model="queryLike.runtime" placeholder="输入运行时间"></el-input>
    </el-form-item>
    <br>
    <el-form-item label="运行结果">
      <el-input v-model="queryLike.result" placeholder="输入运行结果"></el-input>
    </el-form-item>
    <br>
    <el-form-item label="排序类型">
      <el-radio-group v-model="queryLike.sortType">
        <el-radio :label="1">降序</el-radio>
        <el-radio :label="0">升序</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="排序依据">
      <el-radio-group v-model="queryLike.sortBy">
        <el-radio :label="10">创建时间</el-radio>
        <el-radio :label="2">价格</el-radio>
        <el-radio :label="0">浏览量</el-radio>
        <el-radio :label="1">月销量</el-radio>
        <el-radio :label="3">修改时间</el-radio>
      </el-radio-group>
    </el-form-item>
    <br>
    <el-form-item label="页数">
      <el-input v-model="queryLike.page" width="20" placeholder="输入当前页"></el-input>
    </el-form-item>
    <el-form-item label="页内条数">
      <el-input v-model="queryLike.pageSize" width="20" placeholder="输入单页总条数"></el-input>
    </el-form-item>
    <el-form-item>
      <!--查询按钮-->
      <el-button type="primary" @click="search(queryLike)" icon="el-icon-search" value="查询"></el-button>
      <!--添加按钮-->
      <el-button style="float:right" type="success" icon="el-icon-circle-plus-outline" @click="insert()"
                 value="添加"></el-button>
      <!--清空按钮-->
      <el-button v-if="power===3" type="danger" icon="el-icon-delete-solid" @click="clear()"
                 value="清空"></el-button>
    </el-form-item>
  </el-form>
  <!--添加填出的对话框(和修改是同一个)-->
  <el-dialog title="日志" :visible.sync="dialogFormVisible">
    <el-form :model="pojo">
      <el-form-item label="操作员权限" :label-width="formLabelWidth">
        <el-input v-model="pojo.userCode" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="IP地址" :label-width="formLabelWidth">
        <el-input v-model="pojo.ip" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="类型" :label-width="formLabelWidth">
        <el-input v-model="pojo.type" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="内容" :label-width="formLabelWidth">
        <el-input v-model="pojo.describe" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="模块" :label-width="formLabelWidth">
        <el-input v-model="pojo.model" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="运行时长" :label-width="formLabelWidth">
        <el-input v-model="pojo.runtime" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="结果" :label-width="formLabelWidth">
        <el-input v-model="pojo.result" autocomplete="on"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="save(pojo)">确 定</el-button>
    </div>
  </el-dialog>
  <!--内容对话框-->
  <el-dialog
    title="全文"
    :visible.sync="centerDialogVisible"
    width="30%"
    center>
    <p v-html="this.content"></p>
  </el-dialog>
  <!--列表-->
  <el-table :data="user" style="width: 100%" max-height="600">

    <el-table-column fixed property="lid" label="主键"></el-table-column>
    <el-table-column property="userCode" label="操作员权限"></el-table-column>
    <el-table-column property="ip" label="IP地址"></el-table-column>
    <el-table-column property="type" label="操作类型"></el-table-column>
    <el-table-column property="describe" label="具体介绍">
      <template slot-scope="scope" >
        <p v-html="scope.row.describe" class="product-buyer-name"></p>
        <el-button type="text" @click="Content(scope.row.describe)">查看完整内容</el-button>
      </template>
    </el-table-column>
    <el-table-column property="model" label="模块"></el-table-column>
    <el-table-column property="runtime" label="运行时间"></el-table-column>
    <el-table-column property="result" label="结果">
      <template slot-scope="scope" >
        <p v-html="scope.row.result" class="product-buyer-name"></p>
        <el-button type="text" @click="Content(scope.row.result)">查看完整内容</el-button>
      </template>
    </el-table-column>
    <el-table-column property="creattime" label="创建时间" width="150"></el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="200">
      <template slot-scope="scope">
        <el-button type="primary" icon="el-icon-setting" value="修改" @click="change(scope.row)" circle></el-button>
        <el-button v-if="power===3" type="danger" icon="el-icon-delete" value="删除" @click="phydele(scope.row)" circle></el-button>
      </template>
    </el-table-column>
  </el-table>
</div>
</template>

<script>
export default {
  name: "Log",
  props: {},
  data() {
    return {
      /**
       * @介绍内文
       * */
      content:"",
      /**
       * @展示内容
       * */
      centerDialogVisible: false,
      /***
       * @修改和添加数据类型
       * */
      pojo: this.$store.state.Pojo.Log,
      /**
       * @弹出的对话框,用于修改和添加数据
       * */
      dialogFormVisible: false,
      /**
       * @对话框内条目的统一长度
       * */
      formLabelWidth: '120px',
      /**
       * @表单数据
       * */
      user: this.$store.state.List.Log,
      /**
       * @权限,页面显示不同权限的操作
       * */
      power: this.$store.state.operator.power,
      /**
       * @查询条件
       * */
      queryLike: {
        OperatorId: "",
        endTime1: "2099-01-01 00:00:00.000+0000",
        endTime2: "2099-01-01 00:00:00.000+0000",
        describe: "",
        userCode:"",
        ip: "",
        type: "",
        model: "",
        page: 1,
        pageSize: 10,
        sortBy: 10,
        sortType: 1,
        startTime1: "2000-01-01 00:00:00.000+0000",
        startTime2: "2000-01-01 00:00:00.000+0000",
        runtime:"",
        result: "",
      },
      /**
       * @后端controller名字
       * */
      controller:'Log',
    };
  },
  computed: {
    baseURL(){
      return this.$store.state.baseURL;
    }
  },
  /**
   * @加载数据
   */
  created() {
    this.LoadMsg();
  },
  /**
   * @static方法
   * */
  mounted() {
    (() => {
      /*console.log(this.$store.state.operator)
      this.power=this.$store.state.operator["power"];
      console.log(this.power);
      console.log(typeof (this.power))*/
    })();
  },
  methods: {
    /**
     * @清空所有日志
     * */
    clear(){
      let _this = this;
      this.axios.delete(this.$store.state.baseURL + 'client/'+this.controller+'/delete/All?' + 'OperatorId=' + this.$store.state.operator.id )
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @嵌入内容
     * */
    Content(val) {
      this.centerDialogVisible = true;
      this.content = val;
    },
    /**
     * @添加
     * */
    insert() {
      this.pojo = {
        lid: "",
        userCode: -1,
        ip: "",
        creattime: "",
        type: "",
        runtime: "",
        describe: "",
        model: "",
        result: "",
      }
      this.dialogFormVisible = true;
    },
    /**
     * @修改
     * */
    change(val) {
      //console.log(val)
      this.pojo = this.$helper.clone(val);
      this.dialogFormVisible = true;
    },
    /**
     * @保存
     */
    save(val) {
      //console.log(val)
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/'+this.controller+'/save?' + 'OperatorId=' + this.$store.state.operator.id,
        {
          lid: val.lid,
          creattime: "",
          userCode:val.userCode,
          ip: val.ip,
          type: val.type,
          describe: val.describe,
          model: val.model,
          runtime: val.runtime,
          result: val.result
        })
        .then(res => {
          //console.log(res.data)
          _this.search(_this.queryLike);
        })
      this.dialogFormVisible = false;
    },
    /**
     * @物理删除
     */
    phydele(val) {
      let _this = this;
      this.axios.delete(this.$store.state.baseURL + 'client/'+this.controller+'/delete/phy?' + 'OperatorId=' + this.$store.state.operator.id + '&id=' + val.lid)
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @查询
     * */
    search(val) {
      let _this = this;
      //console.log(val);
      this.axios.get(this.$store.state.baseURL + 'client/'+this.controller+'/queryLike?'
        + 'OperatorId=' + this.$store.state.operator.id
        + '&user_code=' + val.userCode
        + '&describe=' + val.describe
        + '&ip=' + val.ip
        + '&type=' + val.type
        + '&sortBy=' + val.sortBy
        + '&sortType=' + val.sortType
        + '&page=' + val.page
        + '&pageSize=' + val.pageSize
        + '&model=' + val.model
        + '&runtime=' + val.runtime
        + '&result=' + val.result
        + '&startTime=' + this.$helper.getDate(val.startTime1).split(' ')[0] + ' ' + this.$helper.getDate(val.startTime2).split(' ')[1]
        + '&endTime=' + this.$helper.getDate(val.endTime1).split(' ')[0] + ' ' + this.$helper.getDate(val.endTime2).split(' ')[1]
      )
        .then(res => {
          _this.$store.state.List.Log = res.data;
          _this.LoadInfo(res.data);
          console.log(res.data);
        })
    }
    ,
    /**
     *
     * @导入具体列表的数据
     */
    LoadMsg() {
      let _this = this;
      this.axios.get(this.$store.state.baseURL + 'client/'+this.controller+'/queryLike?' + 'OperatorId=' + this.$store.state.operator.id )
        .then(res => {
          _this.$store.state.List.Log = res.data;
          _this.LoadInfo(res.data);
          //console.log(res.data);
        })
    }
    ,
    /**
     *
     * @更新当前页面的数据(data<->this.$store.state)
     */
    LoadInfo(val) {
      this.user = val;
    }
    ,
  },
}
</script>

<style scoped>
.product-buyer-name {
  max-width: 180px;
  max-height: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
